package com.example.demo.service;

import com.example.demo.entity.Admin;
import com.example.demo.mapper.AdminMapper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
//愿意交给impl处理
public class AdminImpl implements AdminService{
    @Autowired
    private AdminMapper adminMapper;
    //判断管理员登录用户名和密码正确性
    @Override
    public boolean login(String name, String password) {
        Admin admin = adminMapper.findAdmin(name, password);
        return admin!= null;
    }

    @Override
    public PageInfo<Admin> findAdminPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Admin> lists =adminMapper.findAdminAll();
        PageInfo<Admin> pageInfo=new PageInfo<>(lists);
        return pageInfo;
    }


    @Override
    public List<Admin> findAdminAll(){
        return adminMapper.findAdminAll();
    }



    @Override
    public  Admin findAdminID(Integer admin_id) {
        return adminMapper.findAdminID(admin_id);
    }

    @Override
    public Integer insertAdmin(Admin admin) {


        return adminMapper.insertAdmin(admin);
    }


    @Override
    public Integer updateAdmin(Admin admin) {
        return adminMapper.updateAdmin(admin);
    }

    @Override
    public Integer deleteAdmin(Integer admin_id) {
        return adminMapper.deleteAdmin(admin_id);
    }



}
